Skip to content

Comments

[김은애] sprint4#75

Open
Color-Marker wants to merge 21 commits intocodeit-bootcamp-spring:김은애from
Color-Marker:김은애-sprint4

Hidden character warning

The head ref may contain hidden characters: "\uae40\uc740\uc560-sprint4"
Open

[김은애] sprint4#75
Color-Marker wants to merge 21 commits intocodeit-bootcamp-spring:김은애from
Color-Marker:김은애-sprint4

Conversation

@Color-Marker
Copy link
Collaborator

요구사항

기본

  • 기본 항목 1
  • 기본 항목 2

심화

  • 심화 항목 1
  • 심화 항목 2

주요 변경사항

  • controller를 통해 postman과 작동 확인
  • postman의 컬렉션 정보 json형식으로 export하여 .github 폴더에 추가하여 두었습니다.
  • 예외를 GlobalExceptionHandler로 처리해보았습니다.

멘토에게

  • 전체 예외 처리를 이렇게 하면 되는 건지 궁금합니다.
  • 또한, pathVariable로 UUID를 입력하다보니 상당히 번거로움을 느껴, 개선 방법이 없을지 궁금합니다.

Color-Marker and others added 21 commits January 30, 2026 14:46
public class AuthController {
private final AuthService authService;

@GetMapping("/login")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GET 방식의 URL에 정보가 존재할 경우 패스워드와 같은 숨겨야하는 정보가 노출될 수 있어 POST 방식의 RequestBody으로 처리 권장드려요.

@RequestParam String username,
@RequestParam String password
){
UserLoginReqDto dto = new UserLoginReqDto(username, password);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가적으로, Post 방식으로 호출할 경우 UserLoginReqDto로 변환처리가 필요 없을 것 같아요

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@controller로는 기본적으로 템플릿 명으로 해석되기 때문에 @RestController 사용을 권장드려요.

public class ChannelController {
private final ChannelService channelService;

@PostMapping("/public/create")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restful API 설계상 URL에는 명사만 존재하는걸 권장하기 때문에 행위에 해당하는 create 사용보다는 api/channel/public-channel 식으로 하는걸 권장드려요. 다만 심화 요구사항을 보니 다음 수업때 RestFul API에 관한 설명이 있을 것으로 보여 현시점에서는 참고정도로 부탁드립니다.

return ResponseEntity.ok(result);
}

@PatchMapping("/public/edit/{channelId}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@patch 보다는 @put 사용을 권장드려요.
@patch의 경우 일부 값만 대체하는 개념으로 사용됩니다.


}

@GetMapping("/list/{userId}")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PathVariable 보다는 @RequestParam이 어떠실까요?

채널 리스트를 가져오지만 검색 조건(사용자 ID)에 의해 응답하므로 @RequestParam이 더 타당해보였습니다.

또한 코드를 보지 않고 판단할 경우 UserId 값이 들어갈 부분에 ChannelId로 파악될 수 있어 보여서요.


import java.util.NoSuchElementException;

@ControllerAdvice
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RestControllerAdvice가 어떠실까요?
마찬가지로 @ControllerAdvice는 View 기반(템플릿명)으로 동작하기 때문에 JSON 기반으로 동작하는 RestControllerAdvice를 권장드려요.

import java.util.NoSuchElementException;

@ControllerAdvice
@ResponseBody
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RestControllerAdvice를 사용하면 @responsebody를 사용하지 않아도 됩니다.

@RestControllerAdvice = @ControllerAdvice + @ResponseBody

@PathVariable UUID userId
){
userService.delete(userId);
return ResponseEntity.ok("user: " + userId + "가 삭제되었습니다.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리소스(자원, 사용자)이 삭제되어서 자원이 더 이상 없다는걸 의미해주는 noContent().build()를 활용하시면 어떨까요!?

});
User user = userService.create(userCreateReqDto, binaryDto);
UserDto result = userService.find(user.getId());
return ResponseEntity.ok(result);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  URI location = URI.create("/users/" + user.getId());

    return ResponseEntity
            .created(location)   
            .body(result);

이렇게 201일 경우 자원이 생성되었다는 것을 알 수 있는 created 활용해보시는거 어떠세요?!?

import org.springframework.web.bind.annotation.ResponseBody;

import java.util.NoSuchElementException;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가적으로 controller 패키지 하위보다는 common 패키지 생성 및 하위에 위치시키면 어떨까요?!

@eedys1234
Copy link
Collaborator

전체 예외 처리를 이렇게 하면 되는 건지 궁금합니다.

  1. 전역처리는 구현해주신대로 진행하시면 됩니다.

또한, pathVariable로 UUID를 입력하다보니 상당히 번거로움을 느껴, 개선 방법이 없을지 궁금합니다.

  1. 어느 부분이 번거로운지 알 수 있을까요? 검색 조건으로 사용된다면 RequestParam 을 활용하는 방안이 있습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants